package com.ruoyi.tranShort.controller;

import java.util.List;

import com.ruoyi.tranShort.domain.request.SchedulingRequest;
import com.ruoyi.tranShort.domain.response.EditSchedulingRequest;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.tranShort.domain.ShortScheduling;
import com.ruoyi.tranShort.service.IShortSchedulingService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 排班Controller
 * 
 * @author ruoyi
 * @date 2021-08-14
 */
@Api("排班管理")
@RestController
@RequestMapping("/tranShort/scheduling")
public class ShortSchedulingController extends BaseController
{
    @Autowired
    private IShortSchedulingService shortSchedulingService;

    /**
     * 查询排班列表
     */
    @ApiOperation("查询排班列表")
    @GetMapping("/list")
    public TableDataInfo list(ShortScheduling shortScheduling)
    {
        startPage();
        List<ShortScheduling> list = shortSchedulingService.selectShortSchedulingList(shortScheduling);
        return getDataTable(list);
    }

    /**
     * 导出排班列表
     */
    @PreAuthorize("@ss.hasPermi('tranShort:scheduling:export')")
    @Log(title = "排班", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(ShortScheduling shortScheduling)
    {
        List<ShortScheduling> list = shortSchedulingService.selectShortSchedulingList(shortScheduling);
        ExcelUtil<ShortScheduling> util = new ExcelUtil<ShortScheduling>(ShortScheduling.class);
        return util.exportExcel(list, "排班数据");
    }

    /**
     * 获取排班详细信息
     */
    @ApiOperation("获取排班详细信息")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(shortSchedulingService.selectShortSchedulingById(id));
    }

    /**
     * 新增排班
     */
    @PreAuthorize("@ss.hasPermi('tranShort:scheduling:add')")
    @Log(title = "排班", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ShortScheduling shortScheduling)
    {
        return toAjax(shortSchedulingService.insertShortScheduling(shortScheduling));
    }

    /**
     * 修改排班
     */
    @PreAuthorize("@ss.hasPermi('tranShort:scheduling:edit')")
    @Log(title = "排班", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ShortScheduling shortScheduling)
    {
        return toAjax(shortSchedulingService.updateShortScheduling(shortScheduling));
    }

    /**
     * 删除排班
     */
    @ApiOperation("删除排班")
    @Log(title = "排班", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(shortSchedulingService.deleteShortSchedulingByIds(ids));
    }


    /**
     * 新增排班
     */
    @Log(title = "排班", businessType = BusinessType.INSERT)
    @ApiOperation("新增排班")
    @PostMapping("/save")
    public AjaxResult save(@RequestBody SchedulingRequest schedulingRequest)
    {
        return shortSchedulingService.save(schedulingRequest);
    }

    /**
     * 获取当天排班
     * @return
     */
    @ApiOperation("获取当天排班")
    @GetMapping("/getSchedulingDay")
    public AjaxResult getSchedulingDay(){
        return AjaxResult.success(shortSchedulingService.getSchedulingDay());
    }

    /**
     * 修改排班数据
     * @param editSchedulingRequest
     * @return
     */
    @ApiOperation("修改当天排班")
    @PostMapping("/editScheduling")
    public AjaxResult editScheduling(@RequestBody EditSchedulingRequest editSchedulingRequest){
        return AjaxResult.success(shortSchedulingService.editScheduling(editSchedulingRequest));
    }





}
